package ro.myApp.esb.service;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.mule.api.MuleMessage;
import org.mule.api.MuleSession;
import org.mule.api.routing.RoutingException;
import org.mule.routing.outbound.ChainingRouter;


public class TransactionalChainingRouter extends ChainingRouter {
	
	public MuleMessage routeDefault(MuleMessage message, MuleSession session) throws RoutingException {
		return super.route(message, session);
	}
	
	@Override
	public MuleMessage route(MuleMessage arg0, MuleSession arg1) throws RoutingException {
		
		try {
			return ((EsbTransactionalRouter)InitialContext.doLookup("EsbTransactionalRouterImpl/local")).
				route(this, arg0, arg1);
		} catch (NamingException e) {
			return super.route(arg0, arg1);
		} catch (Throwable e) {
			throw new RuntimeException(e);
		}
	}

}
